package com.weidong.mybbs.util;

public final class UUIDUtil {

    /**
     * 创建指定数量的随机字符串
     * @param numberFlag    是否是数字
     * @param length        长度
     * @return
     */
    public static String randomStr(boolean numberFlag, int length){
        StringBuilder retStr = new StringBuilder();
        String strTable = numberFlag ? "1234567890" : "1234567890abcdefghijklmnppqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int len = strTable.length();
        boolean bDone = true;
        do {
            for (int i = 0; i < length; i++) {
                double dblR = Math.random() * len;
                int intR = (int) Math.floor(dblR);
                retStr.append(strTable.charAt(intR));
            }
            if (retStr.length() >= length) {
                bDone = false;
            }
        } while (bDone);
        return retStr.toString();
    }
}
